package com.beerandjesus.sportofkings.handicapper.app.spring;

import com.beerandjesus.sportofkings.handicapper.dao.Database;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * Date: Sep 10, 2012
 * Time: 9:38:01 PM
 */
@Component
public class HandicapperApplicationListener implements ApplicationListener {

    @Autowired
    private Database database;

    public void onApplicationEvent(ApplicationEvent applicationEvent) {
        if (ContextRefreshedEvent.class.isAssignableFrom(applicationEvent.getClass())) {
            System.out.println("INFO: HandicapperApplicationListener - intializing Database");
            getDatabase().init();
        }
    }

    public Database getDatabase() {
        return database;
    }

    public void setDatabase(Database database) {
        this.database = database;
    }
}
